package part1.api.exception.exceptiontest;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);

        //PrintWriter pp = new PrintWriter("pw.txt"); //直接传文件名就没有自动刷新功能

        Scanner scanner  = new Scanner(System.in);
        System.out.println("请输入要保存的内容，单独输入exit退出");
        while (true){
            String line = scanner.nextLine();
            if ("exit".equals(line)){
                break;
            }
            pw.println(line);
        }
        pw.close();
    }
}
